import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 62536
 * Date: 2023-10-30
 * Time: 18:59
 */
public class Test {



    //求斐波那契数列的第n项。(迭代实现)
    public static int fib(int n){
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static void main7(String[] args) {
        System.out.println(fib(7));

    }

    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值
    public static int max(int a, int b){
        return a > b ? a : b;
    }
    public static double max(double a, double b, double c){
        double d = a > b ? a : b;

        return d > c ? d : c;
    }

    public static void main6(String[] args) {
        System.out.println(max(5, 7));
        System.out.println(max(6.84, 8.54, 7.25));

    }

    //求和的重载
    public static int add(int a, int b){
        return a + b;
    }

    public static int add(int a, int b, int c){
        int d = max2(a,b);
        return a + b + c;
    }
    public static void main5(String[] args) {
        System.out.println(add(3, 5));
        System.out.println(add(3, 5, 7));

    }


    /*创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
    要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算 */
    public static int max2(int a, int b){
        return a > b ? a : b;
    }

    public static int max3(int a, int b, int c){
        int d = max2(a,b);
        return d > c ? d : c;
    }

    public static void main4(String[] args) {
        int a = 5;
        int b = 6;
        int c = 10;
        System.out.println(max3(a, b, c));

    }

    //输出一个数的每一位
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        while(x != 0){
            System.out.println(x % 10);
            x /= 10;
        }
    }

    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
    public static void main2(String[] args) {
        double sum = 0;
        for (double i = 1.0; i <= 100; i++) {
            if(i % 2 != 0){
                sum += 1.0 / i;
            }else {
                sum -= 1.0 / i;
            }
        }
        System.out.println(sum);
    }
}
